CMAKE_MINIMUM_REQUIRED(VERSION 3.17)
PROJECT(EpubPassword)

SET(CMAKE_CXX_STANDARD 17)

ADD_SUBDIRECTORY(m_thrd/openssl)
ADD_SUBDIRECTORY(m_thrd/leveldb)

UNSET(THIRD_PARTY_LIBRARIES)
LIST(APPEND THIRD_PARTY_LIBRARIES
        LIBRARIES::OPENSSL
        LIBRARIES::LEVELDB)

ADD_LIBRARY(EpubPassword STATIC m_apps/m_libraries.cpp)
TARGET_LINK_LIBRARIES(EpubPassword ${THIRD_PARTY_LIBRARIES})
SET_TARGET_PROPERTIES(EpubPassword PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/m_incl/epub_password.h")

ADD_EXECUTABLE(EpubPasswordTest m_apps/m_test.cpp)
TARGET_LINK_LIBRARIES(EpubPasswordTest EpubPassword)

IF (NOT TARGET LIBRARIES::EPUB::PASSWORD)
    ADD_LIBRARY(LIBRARIES::EPUB::PASSWORD OBJECT IMPORTED GLOBAL)
    TARGET_SOURCES(LIBRARIES::EPUB::PASSWORD INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/m_apps/m_libraries.cpp")
    TARGET_INCLUDE_DIRECTORIES(LIBRARIES::EPUB::PASSWORD INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/m_incl")
ENDIF ()

INSTALL(TARGETS EpubPassword EpubPasswordTest
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
        RUNTIME DESTINATION bin
        PUBLIC_HEADER DESTINATION include)